<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Chapter 7 Exploring Data | Data Science at the Command Line, 2e</title>
<meta name="author" content="Jeroen Janssens">
<meta name="description" content="After all that hard work (unless you already had clean data lying around), it’s time for some fun. Now that you have obtained and scrubbed your data, you can continue with the third step of the...">
<meta name="generator" content="bookdown 0.24 with bs4_book()">
<meta property="og:title" content="Chapter 7 Exploring Data | Data Science at the Command Line, 2e">
<meta property="og:type" content="book">
<meta property="og:url" content="https://datascienceatthecommandline.com/chapter-7-exploring-data.html">
<meta property="og:image" content="https://datascienceatthecommandline.com/og.png">
<meta property="og:description" content="After all that hard work (unless you already had clean data lying around), it’s time for some fun. Now that you have obtained and scrubbed your data, you can continue with the third step of the...">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Chapter 7 Exploring Data | Data Science at the Command Line, 2e">
<meta name="twitter:description" content="After all that hard work (unless you already had clean data lying around), it’s time for some fun. Now that you have obtained and scrubbed your data, you can continue with the third step of the...">
<meta name="twitter:image" content="https://datascienceatthecommandline.com/twitter.png">
<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/header-attrs-2.9/header-attrs.js"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="libs/bootstrap-4.6.0/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-4.6.0/bootstrap.bundle.min.js"></script><link href="libs/_Source%20Sans%20Pro-0.4.0/font.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Fira%20Mono:wght@400;600&amp;display=swap" rel="stylesheet">
<script src="libs/bs3compat-0.3.1/transition.js"></script><script src="libs/bs3compat-0.3.1/tabs.js"></script><script src="libs/bs3compat-0.3.1/bs3compat.js"></script><link href="libs/bs4_book-1.0.0/bs4_book.css" rel="stylesheet">
<script src="libs/bs4_book-1.0.0/bs4_book.js"></script><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#d42d2d">
<meta name="apple-mobile-web-app-title" content="Data Science at the Command Line">
<meta name="application-name" content="Data Science at the Command Line">
<meta name="msapplication-TileColor" content="#b91d47">
<meta name="theme-color" content="#ffffff">
<script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-43246574-3', 'auto');
      ga('send', 'pageview');
    </script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- CSS --><link rel="stylesheet" href="dsatcl2e.css">
</head>
<body data-spy="scroll" data-target="#toc">

<div class="container-fluid">
<div class="row">
  <header class="col-sm-12 col-lg-2 sidebar sidebar-book"><a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>

    <div class="d-flex align-items-start justify-content-between">
      <img id="cover" class="d-none d-lg-block" src="images/cover-small.png"><h1 class="d-lg-none">
        <a href="index.html" title="">Data Science at the Command Line, 2e</a>
      </h1>
      <button class="btn btn-outline-primary d-lg-none ml-2 mt-1" type="button" data-toggle="collapse" data-target="#main-nav" aria-expanded="true" aria-controls="main-nav"><i class="fas fa-bars"></i><span class="sr-only">Show table of contents</span></button>
    </div>

    <div id="main-nav" class="collapse-lg">
      <form role="search">
        <input id="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
</form>
      <nav aria-label="Table of contents"><h2>Table of contents</h2>
        <ul class="book-toc list-unstyled">
<li><a class="" href="index.html">Welcome</a></li>
<li><a class="" href="foreword.html">Foreword</a></li>
<li><a class="" href="preface.html">Preface</a></li>
<li><a class="" href="chapter-1-introduction.html"><span class="header-section-number">1</span> Introduction</a></li>
<li><a class="" href="chapter-2-getting-started.html"><span class="header-section-number">2</span> Getting Started</a></li>
<li><a class="" href="chapter-3-obtaining-data.html"><span class="header-section-number">3</span> Obtaining Data</a></li>
<li><a class="" href="chapter-4-creating-command-line-tools.html"><span class="header-section-number">4</span> Creating Command-line Tools</a></li>
<li><a class="" href="chapter-5-scrubbing-data.html"><span class="header-section-number">5</span> Scrubbing Data</a></li>
<li><a class="" href="chapter-6-project-management-with-make.html"><span class="header-section-number">6</span> Project Management with Make</a></li>
<li><a class="active" href="chapter-7-exploring-data.html"><span class="header-section-number">7</span> Exploring Data</a></li>
<li><a class="" href="chapter-8-parallel-pipelines.html"><span class="header-section-number">8</span> Parallel Pipelines</a></li>
<li><a class="" href="chapter-9-modeling-data.html"><span class="header-section-number">9</span> Modeling Data</a></li>
<li><a class="" href="chapter-10-polyglot-data-science.html"><span class="header-section-number">10</span> Polyglot Data Science</a></li>
<li><a class="" href="chapter-11-conclusion.html"><span class="header-section-number">11</span> Conclusion</a></li>
<li><a class="" href="list-of-command-line-tools.html">List of Command-Line Tools</a></li>
</ul>

        <div class="book-extra">
          <p><a id="book-repo" href="https://github.com/jeroenjanssens/data-science-at-the-command-line">View book repository <i class=""></i></a></p>
        </div>

        <div>
          <a id="course-signup" href="/#course">Embrace the Command Line</a>
        </div>
      </nav>
</div>
  </header><main class="col-sm-12 col-md-9 col-lg-7" id="content"><div id="chapter-7-exploring-data" class="section level1" number="7">
<h1>
<span class="header-section-number">7</span> Exploring Data<a class="anchor" aria-label="anchor" href="#chapter-7-exploring-data"><i class="fas fa-link"></i></a>
</h1>
<p>After all that hard work (unless you already had clean data lying around), it’s time for some fun.
Now that you have obtained and scrubbed your data, you can continue with the third step of the OSEMN model, which is to explore it.</p>
<p>Exploring is the step where you familiarize yourself with the data.
Being familiar with the data is essential when you want to extract any value from it.
For example, knowing what kind of features the data has, means you know which ones are worth further exploration and which ones you can use to answer any questions that you have.</p>
<p>Exploring your data can be done from three perspectives.
The first perspective is to inspect the data and its properties.
Here, you want to find out things like what the raw data looks like, how many data points the dataset has, and which features the dataset has.</p>
<p>The second is to compute descriptive statistics. This perspective is useful for learning more about the individual features.
The output is often brief and textual and can therefore be printed on the command line.</p>
<p>The third perspective is to create visualizations of the data. From this perspective you can gain insight into how multiple features interact. I’ll discuss a way of creating visualizations that can be printed on the command line. However, visualizations are best suited to be displayed on a graphical user interface. An advantage of data visualizations over descriptive statistics is that they are more flexible and that they can convey much more information.</p>
<div id="overview-4" class="section level2" number="7.1">
<h2>
<span class="header-section-number">7.1</span> Overview<a class="anchor" aria-label="anchor" href="#overview-4"><i class="fas fa-link"></i></a>
</h2>
<p>In this chapter, you’ll learn how to:</p>
<ul>
<li>Inspect the data and its properties</li>
<li>Compute descriptive statistics</li>
<li>Create data visualizations inside and outside the command line</li>
</ul>
<p>This chapter starts with the following files:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">cd</span> <span style="text-decoration: underline">/data/ch07</span>
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">l</span>
total 104K
-rw-r--r-- 1 dst dst  125 Dec 14 11:49 datatypes.csv
-rw-r--r-- 1 dst dst 7.8K Dec 14 11:49 tips.csv
-rw-r--r-- 1 dst dst  83K Dec 14 11:49 venture.csv
-rw-r--r-- 1 dst dst 4.6K Dec 14 11:49 venture-wide.csv</pre>
<p>The instructions to get these files are in <a href="chapter-2-getting-started.html#chapter-2-getting-started">Chapter 2</a>.
Any other files are either downloaded or generated using command-line tools.</p>
</div>
<div id="inspecting-data-and-its-properties" class="section level2" number="7.2">
<h2>
<span class="header-section-number">7.2</span> Inspecting Data and its Properties<a class="anchor" aria-label="anchor" href="#inspecting-data-and-its-properties"><i class="fas fa-link"></i></a>
</h2>
<p>In this section I’ll demonstrate how to inspect your dataset and its properties. Because the upcoming visualization and modeling techniques expect the data to be in a rectangular shape, I’ll assume that the data is in CSV format. You can use the techniques described in <a href="chapter-5-scrubbing-data.html#chapter-5-scrubbing-data">Chapter 5</a> to convert your data to CSV if necessary.</p>
<p>For simplicity sake, I’ll also assume that your data has a header.
In the first subsection I’ll show a way to determine whether that’s the case.
Once you know you have a header, you can continue answering the following questions:</p>
<ul>
<li>How many data points and features does the dataset have?</li>
<li>What does the raw data look like?</li>
<li>What kind of features does the dataset have?</li>
<li>Can some of these features be treated as categorical?</li>
</ul>
<div id="header-or-not-here-i-come" class="section level3" number="7.2.1">
<h3>
<span class="header-section-number">7.2.1</span> Header Or Not, Here I Come<a class="anchor" aria-label="anchor" href="#header-or-not-here-i-come"><i class="fas fa-link"></i></a>
</h3>
<p>You can check whether your file has a header by printing the first few lines using <code>head</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">head</span> -n 5 <span style="text-decoration: underline">venture.csv</span>
FREQ,TIME_FORMAT,TIME_PERIOD,EXPEND,UNIT,GEO,OBS_STATUS,OBS_VALUE,FREQ_DESC,TIME
_FORMAT_DESC,TIME_PERIOD_DESC,OBS_STATUS_DESC,EXPEND_DESC,UNIT_DESC,GEO_DESC
A,P1Y,2015,INV_VEN,PC_GDP,CZ,,0.002,Annual,Annual,Year 2015,No data,"Venture cap
ital investment (seed, start-up and later stage) ",Percentage of GDP,Czechia
A,P1Y,2007,INV_VEN,PC_GDP,DE,,0.034,Annual,Annual,Year 2007,No data,"Venture cap
ital investment (seed, start-up and later stage) ",Percentage of GDP,Germany
A,P1Y,2008,INV_VEN,PC_GDP,DE,,0.039,Annual,Annual,Year 2008,No data,"Venture cap
ital investment (seed, start-up and later stage) ",Percentage of GDP,Germany
A,P1Y,2009,INV_VEN,PC_GDP,DE,,0.029,Annual,Annual,Year 2009,No data,"Venture cap
ital investment (seed, start-up and later stage) ",Percentage of GDP,Germany</pre>
<p>If the lines wrap around, add line numbers using <code>nl</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">head</span> -n 3 <span style="text-decoration: underline">venture.csv</span> | <span style="color: #5f8700">nl</span>
     1  FREQ,TIME_FORMAT,TIME_PERIOD,EXPEND,UNIT,GEO,OBS_STATUS,OBS_VALUE,FREQ_D
ESC,TIME_FORMAT_DESC,TIME_PERIOD_DESC,OBS_STATUS_DESC,EXPEND_DESC,UNIT_DESC,GEO_
DESC
     2  A,P1Y,2015,INV_VEN,PC_GDP,CZ,,0.002,Annual,Annual,Year 2015,No data,"Ven
ture capital investment (seed, start-up and later stage) ",Percentage of GDP,Cze
chia
     3  A,P1Y,2007,INV_VEN,PC_GDP,DE,,0.034,Annual,Annual,Year 2007,No data,"Ven
ture capital investment (seed, start-up and later stage) ",Percentage of GDP,Ger
many</pre>
<p>Alternatively, you can use <code>trim</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">venture.csv</span> <span style="color: #5f8700">trim</span> 5
FREQ,TIME_FORMAT,TIME_PERIOD,EXPEND,UNIT,GEO,OBS_STATUS,OBS_VALUE,FREQ_DESC,TIM…
A,P1Y,2015,INV_VEN,PC_GDP,CZ,,0.002,Annual,Annual,Year 2015,No data,"Venture ca…
A,P1Y,2007,INV_VEN,PC_GDP,DE,,0.034,Annual,Annual,Year 2007,No data,"Venture ca…
A,P1Y,2008,INV_VEN,PC_GDP,DE,,0.039,Annual,Annual,Year 2008,No data,"Venture ca…
A,P1Y,2009,INV_VEN,PC_GDP,DE,,0.029,Annual,Annual,Year 2009,No data,"Venture ca…
… with 536 more lines</pre>
<p>In this case, it’s clear that the first line is a header because it contains only uppercase names and the subsequent lines contain numbers.
This is indeed quite a subjective process and it’s up to you to decide whether the first line is a header or already the first data point.
When the dataset contains no header, you’re best off using the <code>header</code> tool (discussed in <a href="chapter-5-scrubbing-data.html#chapter-5-scrubbing-data">Chapter 5</a>) to correct that.</p>
</div>
<div id="inspect-all-the-data" class="section level3" number="7.2.2">
<h3>
<span class="header-section-number">7.2.2</span> Inspect All The Data<a class="anchor" aria-label="anchor" href="#inspect-all-the-data"><i class="fas fa-link"></i></a>
</h3>
<p>If you want to inspect the raw data at your own pace, then it’s probably not a good idea to use <code>cat</code>, because then all the data will be printed in one go.
I recommend using <code>less</code><span class="citation"><a class="footnote-ref" tabindex="0" data-toggle="popover" data-content='&lt;p&gt;&lt;a href="#ref-less" role="doc-biblioref"&gt;Mark Nudelman, &lt;em&gt;&lt;span class="nocase"&gt;less&lt;/span&gt; – Opposite of &lt;span class="nocase"&gt;more&lt;/span&gt;&lt;/em&gt;, version 551, 2019, &lt;/a&gt;&lt;a href="https://www.greenwoodsoftware.com/less" role="doc-biblioref"&gt;https://www.greenwoodsoftware.com/less&lt;/a&gt;.&lt;/p&gt;'><sup>90</sup></a></span>, which allows you to interactively inspect your data in the command line.
You can prevent long lines (as with <em>venture.csv</em>) from wrapping by specifying the <code>-S</code> option:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">less</span> -S <span style="text-decoration: underline">venture.csv</span></pre>
<pre>FREQ,TIME_FORMAT,TIME_PERIOD,EXPEND,UNIT,GEO,OBS_STATUS,OBS_VALUE,FREQ_DESC,TIM<span style="font-style: italic">&gt;
</span>A,P1Y,2015,INV_VEN,PC_GDP,CZ,,0.002,Annual,Annual,Year 2015,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2007,INV_VEN,PC_GDP,DE,,0.034,Annual,Annual,Year 2007,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2008,INV_VEN,PC_GDP,DE,,0.039,Annual,Annual,Year 2008,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2009,INV_VEN,PC_GDP,DE,,0.029,Annual,Annual,Year 2009,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2010,INV_VEN,PC_GDP,DE,,0.029,Annual,Annual,Year 2010,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2011,INV_VEN,PC_GDP,DE,,0.029,Annual,Annual,Year 2011,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2012,INV_VEN,PC_GDP,DE,,0.021,Annual,Annual,Year 2012,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2013,INV_VEN,PC_GDP,DE,,0.023,Annual,Annual,Year 2013,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2014,INV_VEN,PC_GDP,DE,,0.021,Annual,Annual,Year 2014,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2015,INV_VEN,PC_GDP,DE,,0.025,Annual,Annual,Year 2015,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2007,INV_VEN,PC_GDP,DK,,0.092,Annual,Annual,Year 2007,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2008,INV_VEN,PC_GDP,DK,,0.074,Annual,Annual,Year 2008,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2009,INV_VEN,PC_GDP,DK,,0.051,Annual,Annual,Year 2009,No data,"Venture ca<span style="font-style: italic">&gt;
</span>A,P1Y,2010,INV_VEN,PC_GDP,DK,,0.059,Annual,Annual,Year 2010,No data,"Venture ca<span style="font-style: italic">&gt;
</span>:                   </pre>
<p>The greater-than signs on the right indicate that you can scroll horizontally.
You can scroll up and down by pressing <strong><code>Up</code></strong> and <strong><code>Down</code></strong>.
Press <strong><code>Space</code></strong> to scroll down an entire screen.
Scrolling horizontally is done by pressing <strong><code>Left</code></strong> and <strong><code>Right</code></strong>.
Press <strong><code>g</code></strong> and <strong><code>G</code></strong> to go to start and the end of the file, respectively.
Quitting <code>less</code> is done by pressing <strong><code>q</code></strong>.
The manual page lists all the available key bindings.</p>
<p>One advantage of <code>less</code> is that it does not load the entire file into memory, which means it’s fast even for viewing large files.</p>
</div>
<div id="feature-names-and-data-types" class="section level3" number="7.2.3">
<h3>
<span class="header-section-number">7.2.3</span> Feature Names and Data Types<a class="anchor" aria-label="anchor" href="#feature-names-and-data-types"><i class="fas fa-link"></i></a>
</h3>
<p>The column (or feature) names may indicate the meaning of the feature.
You can use the following <code>head</code> and <code>tr</code> combo for this:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">venture.csv</span> <span style="color: #5f8700">head</span> -n 1 | <span style="color: #5f8700">tr</span> , <span style="color: #af8700">'\n'</span>
FREQ
TIME_FORMAT
TIME_PERIOD
EXPEND
UNIT
GEO
OBS_STATUS
OBS_VALUE
FREQ_DESC
TIME_FORMAT_DESC
TIME_PERIOD_DESC
OBS_STATUS_DESC
EXPEND_DESC
UNIT_DESC
GEO_DESC</pre>
<p>This basic command assumes that the file is delimited by commas.
A more robust approach is to use <code>csvcut</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvcut</span> -n <span style="text-decoration: underline">venture.csv</span>
  1: FREQ
  2: TIME_FORMAT
  3: TIME_PERIOD
  4: EXPEND
  5: UNIT
  6: GEO
  7: OBS_STATUS
  8: OBS_VALUE
  9: FREQ_DESC
 10: TIME_FORMAT_DESC
 11: TIME_PERIOD_DESC
 12: OBS_STATUS_DESC
 13: EXPEND_DESC
 14: UNIT_DESC
 15: GEO_DESC</pre>
<p>You can go a step further than just printing the column names.
Besides the names of the columns, it would be very useful to know what type of values each column contains, such as a string of characters, a numerical value, or a date.
Assume that you have the following toy dataset:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">bat</span> -A <span style="text-decoration: underline">datatypes.csv</span>
───────┬────────────────────────────────────────────────────────────────────────
       │ File: <span style="font-weight: bold">datatypes.csv</span>
───────┼────────────────────────────────────────────────────────────────────────
   1   │ a,b,c,d,e,f<span style="color: #af005f">␊</span>
   2   │ 1,0.0,FALSE,"""Yes!""",2011-11-11<span style="color: #00afaf">·</span>11:00,2012-09-08<span style="color: #af005f">␊</span>
   3   │ 42,3.1415,TRUE,"OK,<span style="color: #00afaf">·</span>good",2014-09-15,12/6/70<span style="color: #af005f">␊</span>
   4   │ 66,,False,2198,,<span style="color: #af005f">␊</span>
───────┴────────────────────────────────────────────────────────────────────────</pre>
<p>Which <code>csvlook</code> interprets as follows:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvlook</span> <span style="text-decoration: underline">datatypes.csv</span>
│  a │      b │     c │ d        │                   e │          f │
├────┼────────┼───────┼──────────┼─────────────────────┼────────────┤
│  1 │ 0.000… │ False │ "Yes!"   │ 2011-11-11 11:00:00 │ 2012-09-08 │
│ 42 │ 3.142… │  True │ OK, good │ 2014-09-15 00:00:00 │ 1970-12-06 │
│ 66 │        │ False │ 2198     │                     │            │</pre>
<p>I have already used <code>csvsql</code> in <a href="chapter-5-scrubbing-data.html#chapter-5-scrubbing-data">Chapter 5</a> to execute SQL queries directly on CSV data.
When no command-line arguments are passed, it generates the necessary SQL statement that would be needed if you were to insert this data into an actual database.
You can use the output also to inspect what the inferred column types are.
If a column has the <em>NOT NULL</em> string printed after the data type, then that column contains no missing values.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvsql</span> <span style="text-decoration: underline">datatypes.csv</span>
CREATE TABLE datatypes (
        a DECIMAL NOT NULL,
        b DECIMAL,
        c BOOLEAN NOT NULL,
        d VARCHAR NOT NULL,
        e TIMESTAMP,
        f DATE
);</pre>
<p>This output is especially useful when you use other tools within the <code>csvkit</code> suite, such as <code>csvgrep</code>, <code>csvsort</code> and <code>csvsql</code>.
For <em>venture.csv</em>, the columns are inferred as follows:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvsql</span> <span style="text-decoration: underline">venture.csv
</span>CREATE TABLE venture (
        "FREQ" VARCHAR NOT NULL,
        "TIME_FORMAT" VARCHAR NOT NULL,
        "TIME_PERIOD" DECIMAL NOT NULL,
        "EXPEND" VARCHAR NOT NULL,
        "UNIT" VARCHAR NOT NULL,
        "GEO" VARCHAR NOT NULL,
        "OBS_STATUS" BOOLEAN,
        "OBS_VALUE" DECIMAL NOT NULL,
        "FREQ_DESC" VARCHAR NOT NULL,
        "TIME_FORMAT_DESC" VARCHAR NOT NULL,
        "TIME_PERIOD_DESC" VARCHAR NOT NULL,
        "OBS_STATUS_DESC" VARCHAR NOT NULL,
        "EXPEND_DESC" VARCHAR NOT NULL,
        "UNIT_DESC" VARCHAR NOT NULL,
        "GEO_DESC" VARCHAR NOT NULL
);</pre>
</div>
<div id="unique-identifiers-continuous-variables-and-factors" class="section level3" number="7.2.4">
<h3>
<span class="header-section-number">7.2.4</span> Unique Identifiers, Continuous Variables, and Factors<a class="anchor" aria-label="anchor" href="#unique-identifiers-continuous-variables-and-factors"><i class="fas fa-link"></i></a>
</h3>
<p>Knowing the data type of each feature is not enough.
It’s also essential to know what each feature represents.
Having knowledge about the domain is very useful here, but we may also get some context by looking at the data itself.</p>
<p>Both a string and an integer could be a unique identifier or could represent a category.
In the latter case, this could be used to assign a color to your visualization.
But if an integer denotes, say, a postal code, then it doesn’t make sense to compute the average.</p>
<p>To determine whether a feature should be treated as a unique identifier or categorical variable, you could count the number of unique values for a specific column:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">wc</span> -l <span style="text-decoration: underline">tips.csv</span>
245 tips.csv
 
<span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">tips.csv</span> <span style="color: #5f8700">csvcut</span> -c day | <span style="color: #5f8700">header</span> -d | <span style="color: #5f8700">sort</span> | <span style="color: #5f8700">uniq</span> | <span style="color: #5f8700">wc</span> -l
4</pre>
<p>You can use <code>csvstat</code><span class="citation"><a class="footnote-ref" tabindex="0" data-toggle="popover" data-content='&lt;p&gt;&lt;a href="#ref-csvstat" role="doc-biblioref"&gt;Groskopf, &lt;em&gt;&lt;span class="nocase"&gt;csvstat&lt;/span&gt; – Print Descriptive Statistics for Each Column in a &lt;span&gt;CSV&lt;/span&gt; File&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;'><sup>91</sup></a></span>, which is part of <code>csvkit</code>, to get the number of unique values for each column:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvstat</span> <span style="text-decoration: underline">tips.csv</span> --unique
  1. bill: 229
  2. tip: 123
  3. sex: 2
  4. smoker: 2
  5. day: 4
  6. time: 2
  7. size: 6
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">csvstat</span> <span style="text-decoration: underline">venture.csv</span> --unique
  1. FREQ: 1
  2. TIME_FORMAT: 1
  3. TIME_PERIOD: 9
  4. EXPEND: 1
  5. UNIT: 3
  6. GEO: 20
  7. OBS_STATUS: 1
  8. OBS_VALUE: 286
  9. FREQ_DESC: 1
 10. TIME_FORMAT_DESC: 1
 11. TIME_PERIOD_DESC: 9
 12. OBS_STATUS_DESC: 1
 13. EXPEND_DESC: 1
 14. UNIT_DESC: 3
 15. GEO_DESC: 20</pre>
<p>If there’s only one unique value (such as with <em>OBS_STATUS</em>), then there’s a chance that you can discard that column because it doesn’t provide any value.
If you wanted to automatically discard all such columns, then you could use the following pipeline:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">venture.csv</span> <span style="color: #5f8700">csvcut</span> -C <span style="color: #af005f">$(</span> <span class="callout">➊</span>
<span style="font-weight: bold">&gt;</span>   <span style="color: #5f8700">csvstat</span> <span style="text-decoration: underline">venture.csv</span> --unique | <span class="callout">➋</span>
<span style="font-weight: bold">&gt;</span>   <span style="color: #5f8700">grep</span> <span style="color: #af8700">': 1$'</span> | <span class="callout">➌</span>
<span style="font-weight: bold">&gt;</span>   <span style="color: #5f8700">cut</span> -d. -f 1 | <span class="callout">➍</span>
<span style="font-weight: bold">&gt;</span>   <span style="color: #5f8700">tr</span> -d <span style="color: #af8700">' '</span> | <span class="callout">➎</span>
<span style="font-weight: bold">&gt;</span>   <span style="color: #5f8700">paste</span> -sd, <span class="callout">➏</span>
<span style="font-weight: bold">&gt;</span> <span style="color: #af005f">)</span> | <span style="color: #5f8700">trim</span> <span class="callout">➐</span>
TIME_PERIOD,UNIT,GEO,OBS_VALUE,TIME_PERIOD_DESC,UNIT_DESC,GEO_DESC
2015,PC_GDP,CZ,0.002,Year 2015,Percentage of GDP,Czechia
2007,PC_GDP,DE,0.034,Year 2007,Percentage of GDP,Germany
2008,PC_GDP,DE,0.039,Year 2008,Percentage of GDP,Germany
2009,PC_GDP,DE,0.029,Year 2009,Percentage of GDP,Germany
2010,PC_GDP,DE,0.029,Year 2010,Percentage of GDP,Germany
2011,PC_GDP,DE,0.029,Year 2011,Percentage of GDP,Germany
2012,PC_GDP,DE,0.021,Year 2012,Percentage of GDP,Germany
2013,PC_GDP,DE,0.023,Year 2013,Percentage of GDP,Germany
2014,PC_GDP,DE,0.021,Year 2014,Percentage of GDP,Germany
… with 531 more lines</pre>
<p><span class="callout">➊</span> The <code>-C</code> option deselects columns given their locations (or names), which is provided with command substitution
<br><span class="callout">➋</span> Obtain the number of unique values for each column in <em>venture.csv</em>
<br><span class="callout">➌</span> Only keep the columns that contain one unique value
<br><span class="callout">➍</span> Extract the column location
<br><span class="callout">➎</span> Trim any white space
<br><span class="callout">➏</span> Put all column locations on one comma-separated line
<br><span class="callout">➐</span> Only show the first 10 lines</p>
<p>Having said that, I’m going to keep those columns for now.</p>
<p>Generally speaking, if the number of unique values is low compared to the total number of rows, then that feature might be treated as a categorical one (such as <em>GEO</em> in the case of <em>venture.csv</em>).
If the number is equal to the number of rows, it might be a unique identifier but it might also be a numerical value.
There’s only one way to find out: we need to go deeper.</p>
</div>
</div>
<div id="computing-descriptive-statistics" class="section level2" number="7.3">
<h2>
<span class="header-section-number">7.3</span> Computing Descriptive Statistics<a class="anchor" aria-label="anchor" href="#computing-descriptive-statistics"><i class="fas fa-link"></i></a>
</h2>
<div id="column-statistics" class="section level3" number="7.3.1">
<h3>
<span class="header-section-number">7.3.1</span> Column Statistics<a class="anchor" aria-label="anchor" href="#column-statistics"><i class="fas fa-link"></i></a>
</h3>
<p>The command-line tool <code>csvstat</code> gives a lot of information. For each feature (column), it shows:</p>
<ul>
<li>The data type</li>
<li>Whether it has any missing values (nulls)</li>
<li>The number of unique values</li>
<li>Various descriptive statistics (minimum, maximum, sum, mean, standard deviation, and median) for those features for which it is appropriate</li>
</ul>
<p>Invoke <code>csvstat</code> as follows:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvstat</span> <span style="text-decoration: underline">venture.csv</span> | <span style="color: #5f8700">trim</span> 32
  1. "FREQ"
 
        Type of data:          Text
        Contains null values:  False
        Unique values:         1
        Longest value:         1 characters
        Most common values:    A (540x)
 
  2. "TIME_FORMAT"
 
        Type of data:          Text
        Contains null values:  False
        Unique values:         1
        Longest value:         3 characters
        Most common values:    P1Y (540x)
 
  3. "TIME_PERIOD"
 
        Type of data:          Number
        Contains null values:  False
        Unique values:         9
        Smallest value:        2,007
        Largest value:         2,015
        Sum:                   1,085,940
        Mean:                  2,011
        Median:                2,011
        StDev:                 2.584
        Most common values:    2,015 (60x)
                               2,007 (60x)
                               2,008 (60x)
                               2,009 (60x)
                               2,010 (60x)
… with 122 more lines</pre>
<p>I’m only showing the first 32 lines, because this produces a lot of output. You might want to pipe this through <code>less</code>.
If you’re only interested in a specific statistic, you can also use one of the following options:</p>
<ul>
<li>
<code>--max</code> (maximum)</li>
<li>
<code>--min</code> (minimum)</li>
<li>
<code>--sum</code> (sum)</li>
<li>
<code>--mean</code> (mean)</li>
<li>
<code>--median</code> (median)</li>
<li>
<code>--stdev</code> (standard deviation)</li>
<li>
<code>--nulls</code> (whether column contains nulls)</li>
<li>
<code>--unique</code> (unique values)</li>
<li>
<code>--freq</code> (frequent values)</li>
<li>
<code>--len</code> (maximum value length)</li>
</ul>
<p>For example:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvstat</span> <span style="text-decoration: underline">venture.csv</span> --freq | <span style="color: #5f8700">trim</span>
  1. FREQ: { "A": 540 }
  2. TIME_FORMAT: { "P1Y": 540 }
  3. TIME_PERIOD: { "2015": 60, "2007": 60, "2008": 60, "2009": 60, "2010": 60 }
  4. EXPEND: { "INV_VEN": 540 }
  5. UNIT: { "PC_GDP": 180, "NR_COMP": 180, "MIO_EUR": 180 }
  6. GEO: { "CZ": 27, "DE": 27, "DK": 27, "EL": 27, "ES": 27 }
  7. OBS_STATUS: { "None": 540 }
  8. OBS_VALUE: { "0": 28, "1": 19, "2": 14, "0.002": 10, "0.034": 7 }
  9. FREQ_DESC: { "Annual": 540 }
 10. TIME_FORMAT_DESC: { "Annual": 540 }
… with 5 more lines</pre>
<p>You can select a subset of features with the <code>-c</code> option, which accepts both integers and column names:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvstat</span> <span style="text-decoration: underline">venture.csv</span> -c 3,GEO
  3. "TIME_PERIOD"
 
        Type of data:          Number
        Contains null values:  False
        Unique values:         9
        Smallest value:        2,007
        Largest value:         2,015
        Sum:                   1,085,940
        Mean:                  2,011
        Median:                2,011
        StDev:                 2.584
        Most common values:    2,015 (60x)
                               2,007 (60x)
                               2,008 (60x)
                               2,009 (60x)
                               2,010 (60x)
 
  6. "GEO"
 
        Type of data:          Text
        Contains null values:  False
        Unique values:         20
        Longest value:         2 characters
        Most common values:    CZ (27x)
                               DE (27x)
                               DK (27x)
                               EL (27x)
                               ES (27x)
 
Row count: 540</pre>

<div class="rmdtip">
Keep in mind that <code>csvstat</code>, just like <code>csvsql</code>, employs heuristics to determine the data type, and therefore may not always get it right.
I encourage you to always do a manual inspection as discussed in the previous subsection.
Moreover, even though the type may be a string or integer, that doesn’t say anything about how it should be used.
</div>
<p>As a nice extra, <code>csvstat</code> outputs, at the very end, the number of data points (rows).
Newlines and commas inside values are handled correctly.
To only see that last line, you can use <code>tail</code>.
Alternatively, you can use <code>xsv</code>, which only returns the actual number of rows.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">csvstat</span> <span style="text-decoration: underline">venture.csv</span> | <span style="color: #5f8700">tail</span> -n 1
Row count: 540
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">xsv</span> count <span style="text-decoration: underline">venture.csv</span>
540</pre>
<p>Note that these two options are different from using <code>wc -l</code>, which counts the number of newlines (and therefore also counts the header).</p>
</div>
<div id="r-one-liners-on-the-shell" class="section level3" number="7.3.2">
<h3>
<span class="header-section-number">7.3.2</span> R One-Liners on the Shell<a class="anchor" aria-label="anchor" href="#r-one-liners-on-the-shell"><i class="fas fa-link"></i></a>
</h3>
<p>In this section I’d like to introduce you to a command-line tool called <code>rush</code><span class="citation"><a class="footnote-ref" tabindex="0" data-toggle="popover" data-content='&lt;p&gt;&lt;a href="#ref-rush" role="doc-biblioref"&gt;Janssens, &lt;em&gt;&lt;span class="nocase"&gt;rush&lt;/span&gt; – &lt;span&gt;R&lt;/span&gt; One-Liners from the Shell&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;'><sup>92</sup></a></span>,
which enables you to leverage the statistical programming environment <code>R</code><span class="citation"><a class="footnote-ref" tabindex="0" data-toggle="popover" data-content='&lt;p&gt;&lt;a href="#ref-R" role="doc-biblioref"&gt;The R Foundation for Statistical Computing, &lt;em&gt;&lt;span&gt;R&lt;/span&gt; – a Language and Environment for Statistical Computing&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;'><sup>93</sup></a></span> directly from the command line.
Before I explain what <code>rush</code> does and why it exists, lets talk a bit about <code>R</code> itself.</p>
<p><code>R</code> is a very powerful statistical software package to do data science.
It’s an interpreted programming language, has an extensive collection of packages, and offers its own REPL, which allows you, similar to the command line, to play with your data.
Note that, once you start R, you’re in an interactive session that is separated from the Unix command line.</p>
<p>Imagine that you have a CSV file called <em>tips.csv</em>, and you would like compute the tip percentage, and save the result.
To accomplish this in <code>R</code> you would first run, <code>R</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">R</span> --quiet <span class="callout">➊</span>
&gt;</pre>
<p><span class="callout">➊</span> I use the <code>--quiet</code> option here to suppress the rather long startup message</p>
<p>And then run the following code:</p>
<pre>&gt; library(tidyverse)                            <span class="callout">➊</span>
── <span style="font-weight: bold">Attaching packages</span> ─────────────────────────────────────── tidyverse 1.3.0 ──
<span style="color: #5f8700">✔</span> <span style="color: #0087ff">ggplot2</span> 3.3.3     <span style="color: #5f8700">✔</span> <span style="color: #0087ff">purrr  </span> 0.3.4
<span style="color: #5f8700">✔</span> <span style="color: #0087ff">tibble </span> 3.0.6     <span style="color: #5f8700">✔</span> <span style="color: #0087ff">dplyr  </span> 1.0.4
<span style="color: #5f8700">✔</span> <span style="color: #0087ff">tidyr  </span> 1.1.2     <span style="color: #5f8700">✔</span> <span style="color: #0087ff">stringr</span> 1.4.0
<span style="color: #5f8700">✔</span> <span style="color: #0087ff">readr  </span> 1.4.0     <span style="color: #5f8700">✔</span> <span style="color: #0087ff">forcats</span> 0.5.1
── <span style="font-weight: bold">Conflicts</span> ────────────────────────────────────────── tidyverse_conflicts() ──
<span style="color: #d70000">✖</span> <span style="color: #0087ff">dplyr</span>::<span style="color: #5f8700">filter()</span> masks <span style="color: #0087ff">stats</span>::filter()
<span style="color: #d70000">✖</span> <span style="color: #0087ff">dplyr</span>::<span style="color: #5f8700">lag()</span>    masks <span style="color: #0087ff">stats</span>::lag()
&gt; df &lt;- read_csv("tips.csv")                    <span class="callout">➋</span>
 
<span style="color: #00afaf">──</span> <span style="font-weight: bold">Column specification</span> <span style="color: #00afaf">────────────────────────────────────────────────────────
</span>cols(
  bill = <span style="color: #5f8700">col_double()</span>,
  tip = <span style="color: #5f8700">col_double()</span>,
  sex = <span style="color: #d70000">col_character()</span>,
  smoker = <span style="color: #d70000">col_character()</span>,
  day = <span style="color: #d70000">col_character()</span>,
  time = <span style="color: #d70000">col_character()</span>,
  size = <span style="color: #5f8700">col_double()</span>
)
 
&gt; df &lt;- mutate(df, percent = tip / bill * 100)  <span class="callout">➌</span>
&gt; write_csv(df, "percent.csv")                  <span class="callout">➍</span>
&gt; q("no")                                       <span class="callout">➎</span>
 
<span style="font-weight: bold">$</span></pre>
<p><span class="callout">➊</span> Load any required packages
<br><span class="callout">➋</span> Read in the CSV file and assign it to a variable
<br><span class="callout">➌</span> Compute a new column <em>percent</em>
<br><span class="callout">➍</span> Save the result to disk
<br><span class="callout">➎</span> Exit <code>R</code></p>
<p>Afterwards, you can continue with the saved file <em>percent.csv</em> on the command line.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">percent.csv</span> <span style="color: #5f8700">trim</span> 5
bill,tip,sex,smoker,day,time,size,percent
16.99,1.01,Female,No,Sun,Dinner,2,5.9446733372572105
10.34,1.66,Male,No,Sun,Dinner,3,16.054158607350097
21.01,3.5,Male,No,Sun,Dinner,3,16.658733936220845
23.68,3.31,Male,No,Sun,Dinner,2,13.97804054054054
… with 240 more lines</pre>
<p>Note that only the third line is associated with what you want to accomplish specifically.
The other lines are necessary boilerplate.
Typing in this boilerplate in order to accomplish something simple is cumbersome and breaks your workflow.
Sometimes, you only want to do one or two things at a time to your data.
Wouldn’t it be great if you could harness the power of <code>R</code> and to use it from the command line?</p>
<p>This is where <code>rush</code> comes in.
Let’s perform the same task as before, but now using <code>rush</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rm</span> <span style="text-decoration: underline">percent.csv</span>
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> run -t <span style="color: #af8700">'mutate(df, percent = tip / bill * 100)'</span> <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> percent.csv
 
<span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">percent.csv</span> <span style="color: #5f8700">trim</span> 5
bill,tip,sex,smoker,day,time,size,percent
16.99,1.01,Female,No,Sun,Dinner,2,5.9446733372572105
10.34,1.66,Male,No,Sun,Dinner,3,16.054158607350097
21.01,3.5,Male,No,Sun,Dinner,3,16.658733936220845
23.68,3.31,Male,No,Sun,Dinner,2,13.97804054054054
… with 240 more lines</pre>
<p>These small one-liners are possible because <code>rush</code> takes care of all the boilerplate.
In this case I’m using the <code>run</code> subcommand. There’s also the <code>plot</code> subcommand, which I’ll use in the next section to produce data visualizations quickly.
If you’re passing in any input data, then by default, <code>rush</code> assumes that it’s in CSV format with a header and a comma as the delimiter.
Moreover, the column names are sanitized so that they are easier to work with.
You can override these defaults using the <code>--no-header</code> (or <code>-H</code>), <code>--delimiter</code> (or <code>-d</code>), and <code>--no-clean-names</code> (or <code>-C</code>) options, respectively.
The help gives a good overview of the available options for the <code>run</code> subcommand:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> run --help
rush: Run an R expression
 
Usage:
  rush run [options] &lt;expression&gt; [--] [&lt;file&gt;...]
 
Reading options:
  -d, --delimiter &lt;str&gt;    Delimiter [default: ,].
  -C, --no-clean-names     No clean names.
  -H, --no-header          No header.
 
Setup options:
  -l, --library &lt;name&gt;     Libraries to load.
  -t, --tidyverse          Enter the Tidyverse.
 
Saving options:
      --dpi &lt;str|int&gt;      Plot resolution [default: 300].
      --height &lt;int&gt;       Plot height.
  -o, --output &lt;str&gt;       Output file.
      --units &lt;str&gt;        Plot size units [default: in].
  -w, --width &lt;int&gt;        Plot width.
 
General options:
  -n, --dry-run            Only print generated script.
  -h, --help               Show this help.
  -q, --quiet              Be quiet.
      --seed &lt;int&gt;         Seed random number generator.
  -v, --verbose            Be verbose.
      --version            Show version.</pre>
<p>Under the hood, <code>rush</code> generates an <code>R</code> script and subsequently executes it.
You can view this generated script by specifying the <code>--dry-run</code> (or <code>-n</code>) option:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> run -n --tidyverse <span style="color: #af8700">'mutate(df, percent = tip / bill * 100)'</span> <span style="text-decoration: underline">tips.csv</span>
<span style="font-style: italic"></span><span style="font-style: italic; color: #9e9e9e">#!/usr/bin/env Rscript</span>
<span style="color: #00afaf">library</span><span style="color: #af8700">(</span>tidyverse<span style="color: #af8700">)</span>
<span style="color: #00afaf">library</span><span style="color: #af8700">(</span>glue<span style="color: #af8700">)</span>
df <span style="color: #5f8700">&lt;-</span> janitor::<span style="color: #00afaf">clean_names</span><span style="color: #af8700">(</span>readr::<span style="color: #00afaf">read_delim</span><span style="color: #0087ff">(</span><span style="color: #af8700">"tips.csv"</span>, delim = <span style="color: #af8700">","</span>, col_names
= <span style="color: #0087ff">TRUE)</span><span style="color: #af8700">)</span>
<span style="color: #00afaf">mutate</span><span style="color: #af8700">(</span>df, percent = tip<span style="color: #5f8700">/</span>bill <span style="color: #5f8700">*</span> <span style="color: #0087ff">100</span><span style="color: #af8700">)</span></pre>
<p>This generated script:</p>
<ul>
<li>Writes out the shebang (<em><code>#!</code></em>; see <a href="chapter-4-creating-command-line-tools.html#chapter-4-creating-command-line-tools">Chapter 4</a>) needed for running an <code>R</code> script from the command line.</li>
<li>Imports the <em>tidyverse</em> and <em>glue</em> packages.</li>
<li>Loads <em>tips.csv</em> as a data frame, cleans the column names, and assigns it to a variable <em>df</em>.</li>
<li>Runs the specified expression.</li>
<li>Prints the result to standard output.</li>
</ul>
<p>You could redirect this generated script to a file and easily turn it into a new command-line tool because of the shebang.</p>
<p>The output of <code>rush</code> doesn’t have to be a in CSV format per se. Here, I compute the mean tip percent, the maximum party size, the unique values of the time column, the correlation between the bill and the tip. Finally, I extract an entire column (but only show the first 10 values).</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">percent.csv</span> <span style="color: #5f8700">rush</span> run <span style="color: #af8700">'mean(df$percent)'</span> -
16.0802581722505
 
<span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">percent.csv</span> <span style="color: #5f8700">rush</span> run <span style="color: #af8700">'max(df$size)'</span> -
6
 
<span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">percent.csv</span> <span style="color: #5f8700">rush</span> run <span style="color: #af8700">'unique(df$time)'</span> -
Dinner
Lunch
 
<span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">percent.csv</span> <span style="color: #5f8700">rush</span> run <span style="color: #af8700">'cor(df$bill, df$tip)'</span> -
0.675734109211365
 
<span style="font-weight: bold">$</span> <span style="color: #af8700">&lt;</span> <span style="text-decoration: underline">percent.csv</span> <span style="color: #5f8700">rush</span> run <span style="color: #af8700">'df$tip'</span> - | <span style="color: #5f8700">trim</span>
1.01
1.66
3.5
3.31
3.61
4.71
2
3.12
1.96
3.23
… with 234 more lines</pre>
<p>That last dash means that <code>rush</code> should read from standard input.</p>
<p>So now, if you want to do one or two things to your data set with <code>R</code>, you can specify it as a one-liner, and keep on working on the command line.
All the knowledge that you already have about <code>R</code> can now be used from the command line. With <code>rush</code>, you can even create sophisticated visualizations, as I’ll show you in the next section.</p>
</div>
</div>
<div id="creating-visualizations" class="section level2" number="7.4">
<h2>
<span class="header-section-number">7.4</span> Creating Visualizations<a class="anchor" aria-label="anchor" href="#creating-visualizations"><i class="fas fa-link"></i></a>
</h2>
<p>In this section, I’m going to show you how to create data visualizations at the command line.
Using <code>rush plot</code> I’ll be creating bar charts, scatter plots, and box plots.
Before we dive in, though, I’d first like to explain how you can display your visualizations.</p>
<div id="displaying-images-from-the-command-line" class="section level3" number="7.4.1">
<h3>
<span class="header-section-number">7.4.1</span> Displaying Images from the Command Line<a class="anchor" aria-label="anchor" href="#displaying-images-from-the-command-line"><i class="fas fa-link"></i></a>
</h3>
<p>Let’s take the image <em>tips.png</em> as an example.
Take a look at Figure <a href="chapter-7-exploring-data.html#fig:plot-demo">7.1</a>, which is a data visualization created using <code>rush</code> and the <em>tips.csv</em> dataset.
(I’ll explain the <code>rush</code> syntax in a moment.)
I use the <code>display</code> tool to insert the image in the book, but if you run <code>display</code> you’ll find that it doesn’t
work.
That’s because displaying images from the command line is actually quite tricky.</p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-demo"></span>
<img src="images/tips.png" alt="Displaying this image yourself can be tricky" width="90%"><p class="caption">
Figure 7.1: Displaying this image yourself can be tricky
</p>
</div>
<p>Depending on your setup, there are different options available to display images.
I know of four options, each with their own advantages and disadvantages:
(1) as a textual representation,
(2) as an inline image,
(3) using an image viewer, and
(4) using a browser.
Let’s go through them quickly.</p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:screenshot-display-ansi-and-inline"></span>
<img src="images/screenshot_display_ansi_and_inline.png" alt="Displaying an image in the terminal via ASCII characters and ANSI escape sequences (top) and via the iTerm2 inline images protocol (bottom)" width="90%"><p class="caption">
Figure 7.2: Displaying an image in the terminal via ASCII characters and ANSI escape sequences (top) and via the iTerm2 inline images protocol (bottom)
</p>
</div>
<p>Option 1 is to display the image inside the terminal as shown at the top of Figure <a href="chapter-7-exploring-data.html#fig:screenshot-display-ansi-and-inline">7.2</a>.
This output is generated by <code>rush</code> when the standard output is not redirected to a file.
It’s based on ASCII characters and ANSI escape sequences, so it’s available in every terminal.
Depending on how you’re reading this book, the output you get when you run this code might or might not match the screenshot in Figure <a href="chapter-7-exploring-data.html#fig:screenshot-display-ansi-and-inline">7.2</a>.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x bill --y tip --color size --facets <span style="color: #af8700">'~day'</span> <span style="text-decoration: underline">tips.csv</span>              
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #1c1c1c; background: #ffffff">Fri</span><span style="color: #ffffff; background: #ffffff">                               </span><span style="color: #1c1c1c; background: #ffffff">Sat</span><span style="color: #ffffff; background: #ffffff">                     
  </span><span style="color: #4e4e4e; background: #ffffff">10.0</span><span style="color: #ffffff; background: #ffffff">                                                                  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">     
   </span><span style="color: #4e4e4e; background: #ffffff">7.5</span><span style="color: #ffffff; background: #ffffff">                                                            </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">             
                                                           </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">            </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">       
   </span><span style="color: #4e4e4e; background: #ffffff">5.0</span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">               </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">               
            </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">                       </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">##</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #ffffff; background: #5fafd7"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">          
   </span><span style="color: #4e4e4e; background: #ffffff">2.5</span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #005f5f; background: #ffffff"></span><span style="color: #005f5f; background: #005f5f">%</span><span style="color: #5f5f87; background: #005f5f"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">                           </span><span style="color: #005f5f; background: #ffffff"></span><span style="color: #005f5f; background: #005f5f">%</span><span style="color: #ffffff; background: #005f5f"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#########</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">                 
</span><span style="color: #080808; background: #ffffff">t</span><span style="color: #ffffff; background: #ffffff">                                                                          </span><span style="color: #080808; background: #ffffff">size</span><span style="color: #ffffff; background: #ffffff"> 
</span><span style="color: #080808; background: #ffffff">i</span><span style="color: #ffffff; background: #ffffff">                     </span><span style="color: #1c1c1c; background: #ffffff">Sun</span><span style="color: #ffffff; background: #ffffff">                               </span><span style="color: #1c1c1c; background: #ffffff">Thur</span><span style="color: #ffffff; background: #ffffff">                </span><span style="color: #080808; background: #ffffff">6</span><span style="color: #ffffff; background: #ffffff">   
</span><span style="color: #080808; background: #ffffff">p</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">10.0</span><span style="color: #ffffff; background: #ffffff">                                                                      </span><span style="color: #080808; background: #ffffff">1</span><span style="color: #ffffff; background: #ffffff">   
   </span><span style="color: #4e4e4e; background: #ffffff">7.5</span><span style="color: #ffffff; background: #ffffff">                                                         </span><span style="color: #87afff; background: #ffffff"></span><span style="color: #87afff; background: #87afff">=</span><span style="color: #ffffff; background: #87afff"></span><span style="color: #ffffff; background: #ffffff">                
                    </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                           </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                
   </span><span style="color: #4e4e4e; background: #ffffff">5.0</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5fafd7; background: #ffffff"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #5f87af; background: #5fafd7"></span><span style="color: #5f87af; background: #5f87af">#*#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5fafd7; background: #ffffff"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #5f87af; background: #5fafd7"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #87afff; background: #ffffff"></span><span style="color: #87afff; background: #87afff">=</span><span style="color: #ffffff; background: #87afff"></span><span style="color: #ffffff; background: #ffffff">             </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #87afff; background: #ffffff"></span><span style="color: #87afff; background: #87afff">=</span><span style="color: #ffffff; background: #87afff"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #87afff; background: #ffffff"></span><span style="color: #87afff; background: #87afff">=</span><span style="color: #ffffff; background: #87afff"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5fafd7; background: #ffffff"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #5f87af; background: #5fafd7"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">           
   </span><span style="color: #4e4e4e; background: #ffffff">2.5</span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">##</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">            </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">                    
           </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #ffffff; background: #5fafd7"></span><span style="color: #ffffff; background: #ffffff">                   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">######</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                           
           </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">      
                                      </span><span style="color: #080808; background: #ffffff">bill</span><span style="color: #ffffff; background: #ffffff">                                      </span></pre>
<p>If you only see ASCII characters, that means the medium on which you’re reading this book doesn’t support the ANSI escape sequences responsible for the colors.
Fortunately, if you run the above command yourself, it will look just like the screenshot.</p>
<p>Option 2, as seen at the bottom of Figure <a href="chapter-7-exploring-data.html#fig:screenshot-display-ansi-and-inline">7.2</a>, also displays images inside the terminal.
This is the iTerm2 terminal, which is only available for macOS and uses the <a href="https://iterm2.com/documentation-images.html">Inline Images Protocol</a> through a small script (which I have named <code>display</code>).
This script is not included with the Docker image, but you can easily install it:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">curl</span> -s <span style="color: #af8700">"https://iterm2.com/utilities/imgcat"</span> <span style="color: #af8700">&gt;</span> display &amp;&amp; <span style="color: #5f8700">chmod</span> u+x display</pre>
<p>If you’re not using iTerm2 on macOS, there might be other options available to display images inline.
Please consult your favorite search engine.</p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:screenshot-display-preview-and-browser"></span>
<img src="images/screenshot_display_preview_and_browser.png" alt="Displaying an image externally via a file explorer and an image viewer (left) and via a webserver and a browser (right)" width="90%"><p class="caption">
Figure 7.3: Displaying an image externally via a file explorer and an image viewer (left) and via a webserver and a browser (right)
</p>
</div>
<p>Option 3 is to manually open the image (<em>tips.csv</em> in this example) in an image viewer.
Figure <a href="chapter-7-exploring-data.html#fig:screenshot-display-preview-and-browser">7.3</a> shows, on the left, the file explorer (Finder) and image viewer (Preview) on macOS.
When you’re working locally, this option always works.
When you’re working inside a Docker container, you can only access the generated image from your OS when you’ve mapped a local directory using the <code>-v</code> option.
See <a href="chapter-2-getting-started.html#chapter-2-getting-started">Chapter 2</a> for instructions on how to do this.
An advantage of this option is that most image viewers automatically update the display when the image has changed, which allows for quick iterations as you fine-tune your visualization.</p>
<p>Option 4 is to open the image in a browser.
The right side of Figure <a href="chapter-7-exploring-data.html#fig:screenshot-display-preview-and-browser">7.3</a> is a screenshot of Firefox showing <em><a href="http://localhost:8000/tips.png" class="uri">http://localhost:8000/tips.png</a></em>.
Any browser will do, but you need two other prerequisites for this option to work.
First, you need to have made a port (port 8000 in this example) accessible on the Docker container using the <code>-p</code> option.
(Again, see <a href="chapter-2-getting-started.html#chapter-2-getting-started">Chapter 2</a> for instructions on how to do this.)
Second, you need to start a webserver.
For this, the Docker container has a small tool called <code>servewd</code><span class="citation"><a class="footnote-ref" tabindex="0" data-toggle="popover" data-content='&lt;p&gt;&lt;a href="#ref-servewd" role="doc-biblioref"&gt;Jeroen Janssens, &lt;em&gt;&lt;span class="nocase"&gt;servewd&lt;/span&gt; – Serve the Current Working Directory Using a Simple &lt;span&gt;HTTP&lt;/span&gt; Server&lt;/em&gt;, version 0.1, 2021, &lt;/a&gt;&lt;a href="https://github.com/jeroenjanssens/dsutils" role="doc-biblioref"&gt;https://github.com/jeroenjanssens/dsutils&lt;/a&gt;.&lt;/p&gt;'><sup>94</sup></a></span>, which serves the current working directory using Python:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">bat</span> <span style="color: #af005f">$(</span><span style="color: #5f8700">which</span> servewd<span style="color: #af005f">)</span>
───────┬────────────────────────────────────────────────────────────────────────
       │ File: <span style="font-weight: bold">/usr/bin/dsutils/servewd</span>
───────┼────────────────────────────────────────────────────────────────────────
   1   │ <span style="color: #5f8700">#!/usr/bin/env bash</span>
   2   │ ARGS<span style="color: #af005f">=</span><span style="color: #5f8700">"$@"</span>
   3   │ python3 -m http.server ${ARGS} <span style="color: #af8700">2</span><span style="color: #af005f">&gt;</span>/dev/null <span style="color: #af005f">&amp;</span>
───────┴────────────────────────────────────────────────────────────────────────</pre>
<p>You only need to run <code>servewd</code> once from a directory (for example, <em>/data/</em>) and it will happily run in the background.
Once you’ve plotted something, you can visit <em>localhost:8000</em> in your browser and access the contents of that directory and all of its subdirectories.
The default port is 8000, but you can change this by specifying it as an argument to <code>servewd</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">servewd</span> 9999</pre>
<p>Just make sure that this port is accessible.
Because <code>servewd</code> runs in the background, you need to stop it as follows:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">pkill</span> -f http.server</pre>
<p>Option 4 can also work on a remote machine.</p>
<p>Now that we’ve covered four options to display images, let’s move on to actually creating some.</p>
</div>
<div id="plotting-in-a-rush" class="section level3" number="7.4.2">
<h3>
<span class="header-section-number">7.4.2</span> Plotting in a Rush<a class="anchor" aria-label="anchor" href="#plotting-in-a-rush"><i class="fas fa-link"></i></a>
</h3>
<p>When it comes to creating data visualizations, there’s a plethora of options.
Personally, I’m a staunch proponent of <code>ggplot2</code>, which is a visualization package for R.
The underlying grammar of graphics is accompanied by a consistent API that allows you to quickly and iteratively create different types of beautiful data visualizations while rarely having to consult the documentation.
A welcoming set of properties when exploring data.</p>
<p>We’re not really in a rush, but we also don’t want to fiddle too much about any single visualization.
Moreover, we’d like to stay at the command line as much as possible.
Luckily, we still have <code>rush</code>, which allows us to <code>ggplot2</code> from the command line.
The data visualization from Figure <a href="chapter-7-exploring-data.html#fig:plot-demo">7.1</a> could have been created as follows:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> run --library ggplot2 <span style="color: #af8700">'ggplot(df, aes(x = bill, y = tip, color = size)) +
 geom_point() + facet_wrap(~day)'</span> <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> tips.png</pre>
<p>However, as you may have noticed, I have used a very different command to create <em>tips.png</em>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x bill --y tip --color size --facets <span style="color: #af8700">'~day'</span> <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> tips.png</pre>
<p>While the syntax of <code>ggplot2</code> is relatively concise, especially considering the flexibility it offers, there’s a shortcut to create basic plots quickly.
This shortcut is available through the <code>plot</code> subcommand of <code>rush</code>.
This allows you to create beautiful basic plots without needing to learn R and the grammar of graphics.</p>
<p>Under the hood, <code>rush plot</code> uses the function <code>qplot</code> from the <code>ggplot2</code> package.
Here’s the first part of its documentation:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">R</span> -q -e <span style="color: #af8700">'?ggplot2::qplot'</span> | <span style="color: #5f8700">trim</span> 14
&gt; ?ggplot2::qplot
qplot                 package:ggplot2                  R Documentation
 
Quick plot
 
Description:
 
     ‘qplot()’ is a shortcut designed to be familiar if you're used to
     base ‘plot()’. It's a convenient wrapper for creating a number of
     different types of plots using a consistent calling scheme. It's
     great for allowing you to produce plots quickly, but I highly
     recommend learning ‘ggplot()’ as it makes it easier to create
     complex graphics.
 
… with 108 more lines</pre>
<p>I agree with this advice; once you’re done reading this book, it’ll be worthwhile to learn <code>ggplot2</code>, especially if you want to upgrade any exploratory data visualizations into ones that are suitable for communication.
For now, while we’re at the command line, let’s take that shortcut.</p>
<p>As Figure <a href="chapter-7-exploring-data.html#fig:screenshot-display-ansi-and-inline">7.2</a> already showed, <code>rush plot</code> can create both graphical visualizations (consisting of pixels) and textual visualizations (consisting of ASCII characters and ANSI escape sequences) with the same syntax.
When <code>rush</code> detects that its output is piped to another command (such as <code>display</code> or redirected to a file such as <em>tips.png</em> it will produce a graphical visualization; otherwise it will produce a textual visualization.</p>
<p>Let’s take a moment to read through the plotting and saving options of <code>rush plot</code>:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --help
rush: Quick plot
 
Usage:
  rush plot [options] [--] [&lt;file&gt;|-]
 
Reading options:
  -d, --delimiter &lt;str&gt;    Delimiter [default: ,].
  -C, --no-clean-names     No clean names.
  -H, --no-header          No header.
 
Setup options:
  -l, --library &lt;name&gt;     Libraries to load.
  -t, --tidyverse          Enter the Tidyverse.
 
Plotting options:
      --aes &lt;key=value&gt;    Additional aesthetics.
  -a, --alpha &lt;name&gt;       Alpha column.
  -c, --color &lt;name&gt;       Color column.
      --facets &lt;formula&gt;   Facet specification.
  -f, --fill &lt;name&gt;        Fill column.
  -g, --geom &lt;geom&gt;        Geometry [default: auto].
      --group &lt;name&gt;       Group column.
      --log &lt;x|y|xy&gt;       Variables to log transform.
      --margins            Display marginal facets.
      --post &lt;code&gt;        Code to run after plotting.
      --pre &lt;code&gt;         Code to run before plotting.
      --shape &lt;name&gt;       Shape column.
      --size &lt;name&gt;        Size column.
      --title &lt;str&gt;        Plot title.
  -x, --x &lt;name&gt;           X column.
      --xlab &lt;str&gt;         X axis label.
  -y, --y &lt;name&gt;           Y column.
      --ylab &lt;str&gt;         Y axis label.
  -z, --z &lt;name&gt;           Z column.
 
Saving options:
      --dpi &lt;str|int&gt;      Plot resolution [default: 300].
      --height &lt;int&gt;       Plot height.
  -o, --output &lt;str&gt;       Output file.
      --units &lt;str&gt;        Plot size units [default: in].
  -w, --width &lt;int&gt;        Plot width.
 
General options:
  -n, --dry-run            Only print generated script.
  -h, --help               Show this help.
  -q, --quiet              Be quiet.
      --seed &lt;int&gt;         Seed random number generator.
  -v, --verbose            Be verbose.
      --version            Show version.</pre>
<p>The most important options are the plotting options that take a <em><code>&lt;name&gt;</code></em> as an argument.
For example, the <code>--x</code> option allows you to specify which column should be used to determine where <em>things</em> should be placed along the x axis.
The same holds for the <code>--y</code> option.
The <code>--color</code> and <code>--fill</code> options are used to specify which column you want to use for coloring.
You can probably guess what the <code>--size</code> and <code>--alpha</code> options are about.
Other common options are explained throughout the sections as I create various visualizations.
Note that for each visualization, I first show its textual representation (ASCII and ANSI characters) and then its visual representation (pixels).</p>
</div>
<div id="creating-bar-charts" class="section level3" number="7.4.3">
<h3>
<span class="header-section-number">7.4.3</span> Creating Bar Charts<a class="anchor" aria-label="anchor" href="#creating-bar-charts"><i class="fas fa-link"></i></a>
</h3>
<p>Bar charts are especially useful for displaying the value counts of a categorical feature.
Here’s a textual visualization of the <em>time</em> feature in the tips dataset:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x time <span style="text-decoration: underline">tips.csv</span>           
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
  </span><span style="color: #4e4e4e; background: #ffffff">150</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
  </span><span style="color: #4e4e4e; background: #ffffff">100</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">                                       
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">     
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">     
   </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">     
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">     
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">     
         </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">     
    </span><span style="color: #4e4e4e; background: #ffffff">0</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #585858; background: #ffffff"></span><span style="color: #585858; background: #585858">********************************</span><span style="color: #ffffff; background: #585858"></span><span style="color: #ffffff; background: #ffffff">     
                      </span><span style="color: #4e4e4e; background: #ffffff">Dinner</span><span style="color: #ffffff; background: #ffffff">                            </span><span style="color: #4e4e4e; background: #ffffff">Lunch</span><span style="color: #ffffff; background: #ffffff">                   
                                        </span><span style="color: #080808; background: #ffffff">time</span><span style="color: #ffffff; background: #ffffff">                                    </span></pre>
<p>Figure <a href="chapter-7-exploring-data.html#fig:plot-bar-image">7.4</a> shows the graphical visualization, which is created by <code>rush plot</code> when the output is redirected to a file.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x time <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> plot-bar.png
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-bar.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-bar-image"></span>
<img src="images/plot-bar.png" alt="A bar chart" width="90%"><p class="caption">
Figure 7.4: A bar chart
</p>
</div>
<p>The conclusion we can draw from this bar chart is straightforward: there are more than twice as many data points for dinner than lunch.</p>
</div>
<div id="creating-histograms" class="section level3" number="7.4.4">
<h3>
<span class="header-section-number">7.4.4</span> Creating Histograms<a class="anchor" aria-label="anchor" href="#creating-histograms"><i class="fas fa-link"></i></a>
</h3>
<p>The counts of a continuous variable can be visualized with a histogram.
Here, I have used the <em>time</em> feature to set the fill color.
As a result, <code>rush plot</code> conveniently creates a stacked histogram.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x tip --fill time <span style="text-decoration: underline">tips.csv
</span><span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">             </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                                
             </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                        
  </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                        
             </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                        
             </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                        
  </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                        
             </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                 </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #ff8787">t</span><span style="color: #080808; background: #ffffff">ime</span><span style="color: #ffffff; background: #ffffff">   
           </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                                 </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #00d7d7">D</span><span style="color: #080808; background: #ffffff">inner</span><span style="color: #ffffff; background: #ffffff"> 
  </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                               </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #00d7d7">L</span><span style="color: #080808; background: #ffffff">unch</span><span style="color: #ffffff; background: #ffffff">  
           </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                          </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">      
           </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                           
  </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+++++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">==========</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                           
       </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">====</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">====</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                         
       </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++++++++++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">======</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">======</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                              
   </span><span style="color: #4e4e4e; background: #ffffff">0</span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">         
                 </span><span style="color: #4e4e4e; background: #ffffff">2.5</span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #4e4e4e; background: #ffffff">5.0</span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #4e4e4e; background: #ffffff">7.5</span><span style="color: #ffffff; background: #ffffff">             </span><span style="color: #4e4e4e; background: #ffffff">10.0</span><span style="color: #ffffff; background: #ffffff">         
                                     </span><span style="color: #080808; background: #ffffff">tip</span><span style="color: #ffffff; background: #ffffff">                                        </span></pre>
<p>Figure <a href="chapter-7-exploring-data.html#fig:plot-histogram-image">7.5</a> shows the graphical visualization.</p>

<div class="rmdtip">
Allow me to demonstrate two syntax shortcuts that you may find useful.
The two exclamation marks (<code>!!</code>) get replaced with the previous command.
The exclamation mark and dollar sign (<code>!$</code>) get replaced by the last part of the previous command, which is the filename <em>plot-histogram.png</em>.
As you can see, the updated commands are first printed by the Z shell so you know exactly what it executes.
These two shortcuts can save a lot of typing, but they’re not easy to remember.
</div>
<pre><span style="font-weight: bold">$</span> <span style="color: #0087ff">!!</span> <span style="color: #af8700">&gt;</span> plot-histogram.png
rush plot --x tip --fill time tips.csv &gt; plot-histogram.png
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="color: #0087ff">!$</span>
display plot-histogram.png</pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-histogram-image"></span>
<img src="images/plot-histogram.png" alt="A histogram" width="90%"><p class="caption">
Figure 7.5: A histogram
</p>
</div>
<p>This histogram reveals that most tips are around 2,5 USD.
Because the two groups dinner and lunch groups are stacked on top of each other and show absolute counts, it’s difficult to compare them.
Perhaps a density plot can help with this.</p>
</div>
<div id="creating-density-plots" class="section level3" number="7.4.5">
<h3>
<span class="header-section-number">7.4.5</span> Creating Density Plots<a class="anchor" aria-label="anchor" href="#creating-density-plots"><i class="fas fa-link"></i></a>
</h3>
<p>A density plot is useful for visualizing the distribution of a continuous variable.
<code>rush plot</code> uses heuristics to determine the appropriate geometry, but you can override this with the <code>geom</code> option:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x tip --fill time --geom density <span style="text-decoration: underline">tips.csv</span>                         
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #4e4e4e; background: #ffffff">0.5</span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                                                
            </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                                               
  </span><span style="color: #4e4e4e; background: #ffffff">0.4</span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                                              
           </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                                              
           </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">+++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                                         
  </span><span style="color: #4e4e4e; background: #ffffff">0.3</span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@@</span><span style="color: #ff8787; background: #080808"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #080808; background: #ff8787"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                                       
          </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ff8787; background: #080808"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #080808; background: #ff8787"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                               </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">t</span><span style="color: #080808; background: #ffffff">ime</span><span style="color: #ffffff; background: #ffffff">   
          </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ff8787; background: #080808"></span><span style="color: #ff8787; background: #ff8787">====</span><span style="color: #080808; background: #ff8787"></span><span style="color: #080808; background: #080808">@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                              </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">D</span><span style="color: #080808; background: #ffffff">inner</span><span style="color: #ffffff; background: #ffffff"> 
  </span><span style="color: #4e4e4e; background: #ffffff">0.2</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@</span><span style="color: #ff8787; background: #080808"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #080808; background: #ff8787"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                            </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">L</span><span style="color: #080808; background: #ffffff">unch</span><span style="color: #ffffff; background: #ffffff">  
         </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@</span><span style="color: #ff8787; background: #080808"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #080808; background: #ff8787"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                           </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">      
        </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">++++++++++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@@@@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                                
  </span><span style="color: #4e4e4e; background: #ffffff">0.1</span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">@@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++++++++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@@@@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                           
       </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">++++++++++++++++++++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@</span><span style="color: #00d7d7; background: #080808"></span><span style="color: #00d7d7; background: #00d7d7">++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                                        
       </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">++++++++++++++++++++++++++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@@@@@@@@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">                              
  </span><span style="color: #4e4e4e; background: #ffffff">0.0</span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">++++++++++++++++++++++++++++++++++++++++++</span><span style="color: #080808; background: #00d7d7"></span><span style="color: #080808; background: #080808">@@@@@@@@@@@@@@@@@@@@@@</span><span style="color: #ffffff; background: #080808"></span><span style="color: #ffffff; background: #ffffff">         
                 </span><span style="color: #4e4e4e; background: #ffffff">2.5</span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #4e4e4e; background: #ffffff">5.0</span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #4e4e4e; background: #ffffff">7.5</span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #4e4e4e; background: #ffffff">10.0</span><span style="color: #ffffff; background: #ffffff">        
                                     </span><span style="color: #080808; background: #ffffff">tip</span><span style="color: #ffffff; background: #ffffff">                                        </span></pre>
<p>In this case, the textual representation really shows its limitations when compared to the visual representation in Figure <a href="chapter-7-exploring-data.html#fig:plot-density-image">7.6</a>.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x tip --fill time --geom density <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> plot-density.png
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-density.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-density-image"></span>
<img src="images/plot-density.png" alt="A density plot" width="90%"><p class="caption">
Figure 7.6: A density plot
</p>
</div>
</div>
<div id="happy-little-accidents" class="section level3" number="7.4.6">
<h3>
<span class="header-section-number">7.4.6</span> Happy Little Accidents<a class="anchor" aria-label="anchor" href="#happy-little-accidents"><i class="fas fa-link"></i></a>
</h3>
<p>You’ve already seen three types of visualizations.
In <code>ggplot2</code>, these correspond to the functions <code>geom_bar</code>, <code>geom_histogram</code>, and <code>geom_density</code>.
<em>geom</em> is short for geometry and dictates what is actually being plotted.
This <a href="https://ggplot2.tidyverse.org/">cheat sheet for <code>ggplot2</code></a> provides a good overview of the available geometry types.
Which geometry types you can use depend on the columns (and their types) you specify.
Not every combination makes sense.
Take this line plot for example.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x tip --y bill --color size --size day --geom path <span style="text-decoration: underline">tips.csv</span>       
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">                                           </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">               </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">####</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">       
                         </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #87afff; background: #ffffff"></span><span style="color: #87afff; background: #87afff">==</span><span style="color: #ffffff; background: #87afff"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">***</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">            </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">****#####</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">           
                 </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">###</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #87afff; background: #ffffff"></span><span style="color: #87afff; background: #87afff">=</span><span style="color: #5f87af; background: #87afff"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #ffffff; background: #5fafd7"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">***</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*****####</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                
  </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">###***</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #87afff; background: #5fafd7"></span><span style="color: #87afff; background: #87afff">======</span><span style="color: #ffffff; background: #87afff"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*****###</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                     
                   </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#*#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">******###</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #5f5f87; background: #5fafd7"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #87afff; background: #ffffff"></span><span style="color: #87afff; background: #87afff">======</span><span style="color: #5f87af; background: #87afff"></span><span style="color: #5f87af; background: #5f87af">****###</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                    </span><span style="color: #080808; background: #ffffff">day</span><span style="color: #ffffff; background: #ffffff">  
        </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">################</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*****</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #5f87af; background: #5fafd7"></span><span style="color: #5f87af; background: #5f87af">*##*****</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #87afff; background: #5f5f87"></span><span style="color: #87afff; background: #87afff">=</span><span style="color: #5f87af; background: #87afff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                         </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">F</span><span style="color: #080808; background: #ffffff">ri</span><span style="color: #ffffff; background: #ffffff">  
</span><span style="color: #080808; background: #ffffff">b</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+++</span><span style="color: #5f87af; background: #5fafd7"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #87afff; background: #5f5f87"></span><span style="color: #87afff; background: #87afff">==</span><span style="color: #5f87af; background: #87afff"></span><span style="color: #5f87af; background: #5f87af">****</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">+</span><span style="color: #5f87af; background: #5fafd7"></span><span style="color: #5f87af; background: #5f87af">****</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                            </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">S</span><span style="color: #080808; background: #ffffff">at</span><span style="color: #ffffff; background: #ffffff">  
</span><span style="color: #080808; background: #ffffff">i</span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*##</span><span style="color: #5fafd7; background: #5f87af"></span><span style="color: #5fafd7; background: #5fafd7">++</span><span style="color: #5f87af; background: #5fafd7"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">###</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #87afff; background: #5f5f87"></span><span style="color: #87afff; background: #87afff">===</span><span style="color: #5f87af; background: #87afff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #005f5f; background: #5f87af"></span><span style="color: #005f5f; background: #005f5f">%</span><span style="color: #87afff; background: #005f5f"></span><span style="color: #87afff; background: #87afff">=====</span><span style="color: #5f5f87; background: #87afff"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">**#</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                             </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">S</span><span style="color: #080808; background: #ffffff">un</span><span style="color: #ffffff; background: #ffffff">  
</span><span style="color: #080808; background: #ffffff">l</span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">##</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">***</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #87afff; background: #5f5f87"></span><span style="color: #87afff; background: #87afff">=</span><span style="color: #5f5f87; background: #87afff"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #87afff; background: #5f5f87"></span><span style="color: #87afff; background: #87afff">==</span><span style="color: #5f5f87; background: #87afff"></span><span style="color: #5f5f87; background: #5f5f87">##########</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                            </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #080808">T</span><span style="color: #080808; background: #ffffff">hur</span><span style="color: #ffffff; background: #ffffff"> 
</span><span style="color: #080808; background: #ffffff">l</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">########</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">**</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">****</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#####</span><span style="color: #5fafd7; background: #5f5f87"></span><span style="color: #5fafd7; background: #5fafd7">++</span><span style="color: #ffffff; background: #5fafd7"></span><span style="color: #ffffff; background: #ffffff">                                            
       </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">##</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#####</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">###*#</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">#####</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                                       </span><span style="color: #080808; background: #ffffff">size</span><span style="color: #ffffff; background: #ffffff"> 
       </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#########</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">##</span><span style="color: #5f5f87; background: #5f87af"></span><span style="color: #5f5f87; background: #5f5f87">###########</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #5f87af; background: #ffffff"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                                      </span><span style="color: #080808; background: #ffffff">5</span><span style="color: #ffffff; background: #ffffff">    
  </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">###########</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">####</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #5f87af; background: #5f5f87"></span><span style="color: #5f87af; background: #5f87af">*</span><span style="color: #ffffff; background: #5f87af"></span><span style="color: #ffffff; background: #ffffff">                                          
       </span><span style="color: #005f5f; background: #ffffff"></span><span style="color: #005f5f; background: #005f5f">%%</span><span style="color: #5f5f87; background: #005f5f"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">##</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #5f5f87; background: #ffffff"></span><span style="color: #5f5f87; background: #5f5f87">#</span><span style="color: #ffffff; background: #5f5f87"></span><span style="color: #ffffff; background: #ffffff">                                          
       </span><span style="color: #005f5f; background: #ffffff"></span><span style="color: #005f5f; background: #005f5f">%</span><span style="color: #ffffff; background: #005f5f"></span><span style="color: #ffffff; background: #ffffff">                                                                        
                </span><span style="color: #4e4e4e; background: #ffffff">2.5</span><span style="color: #ffffff; background: #ffffff">               </span><span style="color: #4e4e4e; background: #ffffff">5.0</span><span style="color: #ffffff; background: #ffffff">               </span><span style="color: #4e4e4e; background: #ffffff">7.5</span><span style="color: #ffffff; background: #ffffff">               </span><span style="color: #4e4e4e; background: #ffffff">10.0</span><span style="color: #ffffff; background: #ffffff">      
                                      </span><span style="color: #080808; background: #ffffff">tip</span><span style="color: #ffffff; background: #ffffff">                                       </span></pre>
<p>This happy little accident becomes clearer in the visual representation in Figure <a href="chapter-7-exploring-data.html#fig:plot-accident-image">7.7</a>.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x tip --y bill --color size --size day --geom path <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> plot
-accident.png
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-accident.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-accident-image"></span>
<img src="images/plot-accident.png" alt="A happy little accident" width="90%"><p class="caption">
Figure 7.7: A happy little accident
</p>
</div>
<p>The rows in <em>tips.csv</em> are independent observations, whereas drawing a line between the data points assumes that they are connected.
It’s better to visualize the relationship between the <em>tip</em> and the <em>bill</em> with a scatter plot.</p>
</div>
<div id="creating-scatter-plots" class="section level3" number="7.4.7">
<h3>
<span class="header-section-number">7.4.7</span> Creating Scatter Plots<a class="anchor" aria-label="anchor" href="#creating-scatter-plots"><i class="fas fa-link"></i></a>
</h3>
<p>A scatter plot, where the geometry is a point, happens to be the default when specifying two continuous features:</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x bill --y tip --color time <span style="text-decoration: underline">tips.csv</span>                              
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #4e4e4e; background: #ffffff">10.0</span><span style="color: #ffffff; background: #ffffff">                                                                </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">         
                                                                   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">            
                                                                                
                                                                                
   </span><span style="color: #4e4e4e; background: #ffffff">7.5</span><span style="color: #ffffff; background: #ffffff">                                                 </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                        
                                  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">                </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">             
</span><span style="color: #080808; background: #ffffff">t</span><span style="color: #ffffff; background: #ffffff">                                   </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                          </span><span style="color: #080808; background: #ffffff">time</span><span style="color: #ffffff; background: #ffffff">   
</span><span style="color: #080808; background: #ffffff">i</span><span style="color: #ffffff; background: #ffffff">             </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">                       </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #ff8787">D</span><span style="color: #080808; background: #ffffff">inner</span><span style="color: #ffffff; background: #ffffff"> 
</span><span style="color: #080808; background: #ffffff">p</span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #4e4e4e; background: #ffffff">5.0</span><span style="color: #ffffff; background: #ffffff">                         </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #00d7d7">L</span><span style="color: #080808; background: #ffffff">unch</span><span style="color: #ffffff; background: #ffffff">  
                 </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                          
                   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">========</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">             </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                
                  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=====</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=====</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">++</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                  
   </span><span style="color: #4e4e4e; background: #ffffff">2.5</span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">++++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">====</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                   
              </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #00d7d7; background: #ffffff"></span><span style="color: #00d7d7; background: #00d7d7">+</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">==</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">++</span><span style="color: #ffffff; background: #00d7d7"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                         
        </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                    </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">                                
                 </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">          
                                     </span><span style="color: #080808; background: #ffffff">bill</span><span style="color: #ffffff; background: #ffffff">                                       </span></pre>
<p>Note that the color of each point is specified with the <code>--color</code> option (and not with the <code>--fill</code> option).
See Figure <a href="chapter-7-exploring-data.html#fig:plot-scatter-image">7.8</a> for the visual representation.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x bill --y tip --color time <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> plot-scatter.png
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-scatter.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-scatter-image"></span>
<img src="images/plot-scatter.png" alt="A scatter plot" width="90%"><p class="caption">
Figure 7.8: A scatter plot
</p>
</div>
<p>From this scatter plot we may conclude that there’s a relationship between the amount of the bill and the tip.
Perhaps we it’s useful to examine this data from a higher level by creating trend lines.</p>
</div>
<div id="creating-trend-lines" class="section level3" number="7.4.8">
<h3>
<span class="header-section-number">7.4.8</span> Creating Trend Lines<a class="anchor" aria-label="anchor" href="#creating-trend-lines"><i class="fas fa-link"></i></a>
</h3>
<p>If you override the default geometry with <em><code>smooth</code></em>, you can visualize trend lines.
These are useful for seeing the bigger picture.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x bill --y tip --color time --geom smooth <span style="text-decoration: underline">tips.csv</span>                
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">                                                                     </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">==</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">         
                                                                   </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">====</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">         
  </span><span style="color: #4e4e4e; background: #ffffff">7.5</span><span style="color: #ffffff; background: #ffffff">                                                            </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">===</span><span style="color: #ff8787; background: #949494"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #ffffff; background: #ff8787"></span><span style="color: #ffffff; background: #ffffff">         
                                                               </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">==</span><span style="color: #ff8787; background: #949494"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #949494; background: #ff8787"></span><span style="color: #949494; background: #949494">===</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">         
                                                     </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">=========</span><span style="color: #ff8787; background: #949494"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #949494; background: #ff8787"></span><span style="color: #949494; background: #949494">======</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">         
                                             </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">=======</span><span style="color: #00d7d7; background: #949494"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++</span><span style="color: #ff8787; background: #00d7d7"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #949494; background: #ff8787"></span><span style="color: #949494; background: #949494">=====</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">             
</span><span style="color: #080808; background: #ffffff">t</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">5.0</span><span style="color: #ffffff; background: #ffffff">                                  </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">====</span><span style="color: #00d7d7; background: #949494"></span><span style="color: #00d7d7; background: #00d7d7">+++++++++</span><span style="color: #949494; background: #00d7d7"></span><span style="color: #949494; background: #949494">==========</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #949494">t</span><span style="color: #080808; background: #ffffff">ime</span><span style="color: #ffffff; background: #ffffff">   
</span><span style="color: #080808; background: #ffffff">i</span><span style="color: #ffffff; background: #ffffff">                                 </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">====</span><span style="color: #00d7d7; background: #949494"></span><span style="color: #00d7d7; background: #00d7d7">++++++</span><span style="color: #949494; background: #00d7d7"></span><span style="color: #949494; background: #949494">======</span><span style="color: #ff8787; background: #949494"></span><span style="color: #ff8787; background: #ff8787">===</span><span style="color: #949494; background: #ff8787"></span><span style="color: #949494; background: #949494">========</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">            </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #949494">D</span><span style="color: #080808; background: #ffffff">inner</span><span style="color: #ffffff; background: #ffffff"> 
</span><span style="color: #080808; background: #ffffff">p</span><span style="color: #ffffff; background: #ffffff">                           </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">===</span><span style="color: #00d7d7; background: #949494"></span><span style="color: #00d7d7; background: #00d7d7">+++++++</span><span style="color: #949494; background: #00d7d7"></span><span style="color: #949494; background: #949494">====</span><span style="color: #ff8787; background: #949494"></span><span style="color: #ff8787; background: #ff8787">=</span><span style="color: #949494; background: #ff8787"></span><span style="color: #949494; background: #949494">========</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #080808; background: #ffffff"></span><span style="color: #080808; background: #00d7d7">L</span><span style="color: #080808; background: #ffffff">unch</span><span style="color: #ffffff; background: #ffffff">  
       </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">==</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">==</span><span style="color: #00d7d7; background: #949494"></span><span style="color: #00d7d7; background: #00d7d7">+++++++</span><span style="color: #949494; background: #00d7d7"></span><span style="color: #949494; background: #949494">=====</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">                                    </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">=</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">      
  </span><span style="color: #4e4e4e; background: #ffffff">2.5</span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">==============</span><span style="color: #00d7d7; background: #949494"></span><span style="color: #00d7d7; background: #00d7d7">++++</span><span style="color: #949494; background: #00d7d7"></span><span style="color: #949494; background: #949494">====</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">                                                   
       </span><span style="color: #ff8787; background: #ffffff"></span><span style="color: #ff8787; background: #ff8787">======</span><span style="color: #00d7d7; background: #ff8787"></span><span style="color: #00d7d7; background: #00d7d7">++++++++</span><span style="color: #949494; background: #00d7d7"></span><span style="color: #949494; background: #949494">===</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">                                                        
       </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">==========</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">                                                               
       </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">=====</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">                                                                    
  </span><span style="color: #4e4e4e; background: #ffffff">0.0</span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #949494; background: #ffffff"></span><span style="color: #949494; background: #949494">==</span><span style="color: #ffffff; background: #949494"></span><span style="color: #ffffff; background: #ffffff">                                                                       
                </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">          
                                     </span><span style="color: #080808; background: #ffffff">bill</span><span style="color: #ffffff; background: #ffffff">                                       </span></pre>
<p><code>rush plot</code> cannot handle transparency, so a visual representation (see Figure <a href="chapter-7-exploring-data.html#fig:plot-trend-image">7.9</a> is much better in this case.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x bill --y tip --color time --geom smooth <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> plot-trend.pn
g
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-trend.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-trend-image"></span>
<img src="images/plot-trend.png" alt="Trend lines" width="90%"><p class="caption">
Figure 7.9: Trend lines
</p>
</div>
<p>If you like to visualize the original points along with the trend lines, you need to resort to writing <code>ggplot2</code> code with <code>rush run</code> (see Figure <a href="chapter-7-exploring-data.html#fig:plot-trend-points-image">7.10</a>).</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> run --library ggplot2 <span style="color: #af8700">'ggplot(df, aes(x = bill, y = tip, color = time)) +
 geom_point() + geom_smooth()'</span> <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> plot-trend-points.png
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-trend-points.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-trend-points-image"></span>
<img src="images/plot-trend-points.png" alt="Trend lines and original points combined" width="90%"><p class="caption">
Figure 7.10: Trend lines and original points combined
</p>
</div>
</div>
<div id="creating-box-plots" class="section level3" number="7.4.9">
<h3>
<span class="header-section-number">7.4.9</span> Creating Box Plots<a class="anchor" aria-label="anchor" href="#creating-box-plots"><i class="fas fa-link"></i></a>
</h3>
<p>A box plot visualizes, for one or more features, a five-number summary: the minimum, the maximum, the sample median, and the first and third quartiles.
In this case we need to convert the <em>size</em> feature to a categorical one using the <code><a href="https://rdrr.io/r/base/factor.html">factor()</a></code> function, otherwise all values of the <em>bill</em> feature will be lumped together.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x <span style="color: #af8700">'factor(size)'</span> --y bill --geom boxplot <span style="text-decoration: underline">tips.csv</span>                 
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">                               </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                            
                                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       
                                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       
  </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">            </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       
                                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">   
                       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">   
</span><span style="color: #080808; background: #ffffff">b</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">                               </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">   
</span><span style="color: #080808; background: #ffffff">i</span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                           
</span><span style="color: #080808; background: #ffffff">l</span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                           
</span><span style="color: #080808; background: #ffffff">l</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">              </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                    
                  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                       
                  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                            
  </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                                        
      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                                                
                                                                                
          </span><span style="color: #4e4e4e; background: #ffffff">1</span><span style="color: #ffffff; background: #ffffff">            </span><span style="color: #4e4e4e; background: #ffffff">2</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">3</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">4</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">5</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">6</span><span style="color: #ffffff; background: #ffffff">        
                                   </span><span style="color: #080808; background: #ffffff">factor(size)</span><span style="color: #ffffff; background: #ffffff">                                 </span></pre>
<p>While the textual representation is not too bad, the visual one is much clearer (see Figure <a href="chapter-7-exploring-data.html#fig:plot-boxplot-image">7.11</a>).</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x <span style="color: #af8700">'factor(size)'</span> --y bill --geom boxplot <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> plot-boxplot.p
ng
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-boxplot.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-boxplot-image"></span>
<img src="images/plot-boxplot.png" alt="A box plot" width="90%"><p class="caption">
Figure 7.11: A box plot
</p>
</div>
<p>Unsurprisingly, this box plot shows that, on average, a larger party size leads to a higher bill.</p>
</div>
<div id="adding-labels" class="section level3" number="7.4.10">
<h3>
<span class="header-section-number">7.4.10</span> Adding Labels<a class="anchor" aria-label="anchor" href="#adding-labels"><i class="fas fa-link"></i></a>
</h3>
<p>The default labels are based on column names (or specification).
In the previous image, the label <em><code>factor(size)</code></em> should be improved.
Using the <code>--xlab</code> and <code>--ylab</code> options you can override the labels of the x and y axes.
A title can be added with the <code>--title</code> option.
Here’s a violin plot (which is a mashup of a box plot and a density plot) demonstrating this (see also Figure <a href="chapter-7-exploring-data.html#fig:plot-labels-image">7.12</a>.</p>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x <span style="color: #af8700">'factor(size)'</span> --y bill --geom violin --title <span style="color: #af8700">'Distribution of b
ill amount per party size'</span> --xlab <span style="color: #af8700">'Party size'</span> --ylab <span style="color: #af8700">'Bill (USD)'</span> <span style="text-decoration: underline">tips.csv</span>     
<span style="color: #ffffff"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #080808; background: #ffffff">Distribution</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #080808; background: #ffffff">of</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #080808; background: #ffffff">bill</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #080808; background: #ffffff">amount</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #080808; background: #ffffff">per</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #080808; background: #ffffff">party</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #080808; background: #ffffff">size</span><span style="color: #ffffff; background: #ffffff">                                   
  </span><span style="color: #4e4e4e; background: #ffffff">50</span><span style="color: #ffffff; background: #ffffff">                               </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                            
                                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       
                                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       
  </span><span style="color: #4e4e4e; background: #ffffff">40</span><span style="color: #ffffff; background: #ffffff">                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       
</span><span style="color: #080808; background: #ffffff">B</span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">      
</span><span style="color: #080808; background: #ffffff">i</span><span style="color: #ffffff; background: #ffffff">                      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">     
</span><span style="color: #080808; background: #ffffff">l</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">30</span><span style="color: #ffffff; background: #ffffff">                  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">          </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">     
</span><span style="color: #080808; background: #ffffff">l</span><span style="color: #ffffff; background: #ffffff">                     </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">         </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                   
                     </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                 
</span><span style="color: #080808; background: #ffffff">(</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">20</span><span style="color: #ffffff; background: #ffffff">                </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                              
</span><span style="color: #080808; background: #ffffff">U</span><span style="color: #ffffff; background: #ffffff">                   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">      </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                          
</span><span style="color: #080808; background: #ffffff">S</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #4e4e4e; background: #ffffff">10</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">   </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">        </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                           
</span><span style="color: #080808; background: #ffffff">D</span><span style="color: #ffffff; background: #ffffff">    </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">  </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">     </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                                       
</span><span style="color: #080808; background: #ffffff">)</span><span style="color: #ffffff; background: #ffffff">       </span><span style="color: #3a3a3a; background: #ffffff"></span><span style="color: #3a3a3a; background: #3a3a3a">%%%%%%</span><span style="color: #ffffff; background: #3a3a3a"></span><span style="color: #ffffff; background: #ffffff">                                                                  
          </span><span style="color: #4e4e4e; background: #ffffff">1</span><span style="color: #ffffff; background: #ffffff">            </span><span style="color: #4e4e4e; background: #ffffff">2</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">3</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">4</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">5</span><span style="color: #ffffff; background: #ffffff">           </span><span style="color: #4e4e4e; background: #ffffff">6</span><span style="color: #ffffff; background: #ffffff">        
                                    </span><span style="color: #080808; background: #ffffff">Party</span><span style="color: #ffffff; background: #ffffff"> </span><span style="color: #080808; background: #ffffff">size</span><span style="color: #ffffff; background: #ffffff">                                  </span></pre>
<pre><span style="font-weight: bold">$</span> <span style="color: #5f8700">rush</span> plot --x <span style="color: #af8700">'factor(size)'</span> --y bill --geom violin --title <span style="color: #af8700">'Distribution of b
ill amount per party size'</span> --xlab <span style="color: #af8700">'Party size'</span> --ylab <span style="color: #af8700">'Bill (USD)'</span> <span style="text-decoration: underline">tips.csv</span> <span style="color: #af8700">&gt;</span> pl
ot-labels.png
 
<span style="font-weight: bold">$</span> <span style="color: #5f8700">display</span> <span style="text-decoration: underline">plot-labels.png</span></pre>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:plot-labels-image"></span>
<img src="images/plot-labels.png" alt="A violin plot with a title and labels" width="90%"><p class="caption">
Figure 7.12: A violin plot with a title and labels
</p>
</div>
<p>Annotating your visualization with proper labels and a title is especially useful if you want to share it with others (or your future self) so that it’s easier to understand what’s being shown.</p>
</div>
<div id="going-beyond-basic-plots" class="section level3" number="7.4.11">
<h3>
<span class="header-section-number">7.4.11</span> Going Beyond Basic Plots<a class="anchor" aria-label="anchor" href="#going-beyond-basic-plots"><i class="fas fa-link"></i></a>
</h3>
<p>Although <code>rush plot</code> is suitable for creating basic plots when you’re exploring data, it certainly has its limitations.
Sometimes you need more flexibility and sophisticated options such as multiple geometries, coordinate transformations, and theming.
In that case it might be worthwhile to learn more about the underlying package from which <code>rush plot</code> draws its capabilities, namely the <code>ggplot2</code> package for R.
When you’re more into Python than R, there’s the <a href="https://plotnine.readthedocs.io"><code>plotnine</code> package</a>, which is reimplementation of <code>ggplot2</code> for Python.</p>
</div>
</div>
<div id="summary-6" class="section level2" number="7.5">
<h2>
<span class="header-section-number">7.5</span> Summary<a class="anchor" aria-label="anchor" href="#summary-6"><i class="fas fa-link"></i></a>
</h2>
<p>In this chapter we’ve looked at various ways to explore your data.
Both textual and graphical data visualizations have their pros and cons.
The graphical ones are obviously of much higher quality, but can be tricky to view at the command line.
This is where textual visualizations come in handy.
At least <code>rush</code> has, thanks to <code>R</code> and <code>ggplot2</code>, a consistent syntax for creating both types.</p>
<p>The next chapter is, once again, an intermezzo chapter in which I discuss how you can speed up your commands and pipelines.
Feel free to read that chapter later if you can’t wait to start modeling your data in <a href="chapter-9-modeling-data.html#chapter-9-modeling-data">Chapter 9</a>.</p>
</div>
<div id="for-further-exploration-6" class="section level2" number="7.6">
<h2>
<span class="header-section-number">7.6</span> For Further Exploration<a class="anchor" aria-label="anchor" href="#for-further-exploration-6"><i class="fas fa-link"></i></a>
</h2>
<ul>
<li>A proper <code>ggplot2</code> tutorial is unfortunately beyond the scope of this book. If you want to get better at visualizing your data I strongly recommend that you invest some time in understanding the power and beauty of the grammar of graphics. Chapters 3 and 28 of the book <a href="https://r4ds.had.co.nz/"><em>R for Data Science</em></a> by Hadley Wickham and Garrett Grolemund are an excellent resource.</li>
<li>Speaking of Chapters 3 and 28, I <a href="https://datascienceworkshops.com/blog/plotnine-grammar-of-graphics-for-python/">translated those to Python using Plotnine and Pandas</a> in case you’re more into Python than R.</li>
</ul>
</div>
</div>

  <div class="chapter-nav">
<div class="prev"><a href="chapter-6-project-management-with-make.html"><span class="header-section-number">6</span> Project Management with Make</a></div>
<div class="next"><a href="chapter-8-parallel-pipelines.html"><span class="header-section-number">8</span> Parallel Pipelines</a></div>
</div></main><div class="col-md-3 col-lg-3 d-none d-md-block sidebar sidebar-chapter">
    <nav id="toc" data-toggle="toc" aria-label="On this page"><h2>On this page</h2>
      <ul class="nav navbar-nav">
<li><a class="nav-link" href="#chapter-7-exploring-data"><span class="header-section-number">7</span> Exploring Data</a></li>
<li><a class="nav-link" href="#overview-4"><span class="header-section-number">7.1</span> Overview</a></li>
<li>
<a class="nav-link" href="#inspecting-data-and-its-properties"><span class="header-section-number">7.2</span> Inspecting Data and its Properties</a><ul class="nav navbar-nav">
<li><a class="nav-link" href="#header-or-not-here-i-come"><span class="header-section-number">7.2.1</span> Header Or Not, Here I Come</a></li>
<li><a class="nav-link" href="#inspect-all-the-data"><span class="header-section-number">7.2.2</span> Inspect All The Data</a></li>
<li><a class="nav-link" href="#feature-names-and-data-types"><span class="header-section-number">7.2.3</span> Feature Names and Data Types</a></li>
<li><a class="nav-link" href="#unique-identifiers-continuous-variables-and-factors"><span class="header-section-number">7.2.4</span> Unique Identifiers, Continuous Variables, and Factors</a></li>
</ul>
</li>
<li>
<a class="nav-link" href="#computing-descriptive-statistics"><span class="header-section-number">7.3</span> Computing Descriptive Statistics</a><ul class="nav navbar-nav">
<li><a class="nav-link" href="#column-statistics"><span class="header-section-number">7.3.1</span> Column Statistics</a></li>
<li><a class="nav-link" href="#r-one-liners-on-the-shell"><span class="header-section-number">7.3.2</span> R One-Liners on the Shell</a></li>
</ul>
</li>
<li>
<a class="nav-link" href="#creating-visualizations"><span class="header-section-number">7.4</span> Creating Visualizations</a><ul class="nav navbar-nav">
<li><a class="nav-link" href="#displaying-images-from-the-command-line"><span class="header-section-number">7.4.1</span> Displaying Images from the Command Line</a></li>
<li><a class="nav-link" href="#plotting-in-a-rush"><span class="header-section-number">7.4.2</span> Plotting in a Rush</a></li>
<li><a class="nav-link" href="#creating-bar-charts"><span class="header-section-number">7.4.3</span> Creating Bar Charts</a></li>
<li><a class="nav-link" href="#creating-histograms"><span class="header-section-number">7.4.4</span> Creating Histograms</a></li>
<li><a class="nav-link" href="#creating-density-plots"><span class="header-section-number">7.4.5</span> Creating Density Plots</a></li>
<li><a class="nav-link" href="#happy-little-accidents"><span class="header-section-number">7.4.6</span> Happy Little Accidents</a></li>
<li><a class="nav-link" href="#creating-scatter-plots"><span class="header-section-number">7.4.7</span> Creating Scatter Plots</a></li>
<li><a class="nav-link" href="#creating-trend-lines"><span class="header-section-number">7.4.8</span> Creating Trend Lines</a></li>
<li><a class="nav-link" href="#creating-box-plots"><span class="header-section-number">7.4.9</span> Creating Box Plots</a></li>
<li><a class="nav-link" href="#adding-labels"><span class="header-section-number">7.4.10</span> Adding Labels</a></li>
<li><a class="nav-link" href="#going-beyond-basic-plots"><span class="header-section-number">7.4.11</span> Going Beyond Basic Plots</a></li>
</ul>
</li>
<li><a class="nav-link" href="#summary-6"><span class="header-section-number">7.5</span> Summary</a></li>
<li><a class="nav-link" href="#for-further-exploration-6"><span class="header-section-number">7.6</span> For Further Exploration</a></li>
</ul>

      <div class="book-extra">
        <ul class="list-unstyled">
<li><a id="book-source" href="https://github.com/jeroenjanssens/data-science-at-the-command-line/blob/master/book/2e/07.Rmd">View source <i class=""></i></a></li>
          <li><a id="book-edit" href="https://github.com/jeroenjanssens/data-science-at-the-command-line/edit/master/book/2e/07.Rmd">Edit this page <i class=""></i></a></li>
        </ul>
</div>
    </nav>
</div>

</div>
</div> <!-- .container -->

<footer class="bg-primary text-light mt-5"><div class="container-fluid">
    <div class="row">
      <div class="d-none d-lg-block col-lg-2 sidebar"></div>
      <div class="col-sm-12 col-md-9 col-lg-7 mt-3" style="max-width: 45rem;">
        <p><strong>Data Science at the Command Line, 2e</strong> by <a href="https://twitter.com/jeroenhjanssens" class="text-light">Jeroen Janssens</a>. Updated on December 14, 2021. This book was built by the <a class="text-light" href="https://bookdown.org">bookdown</a> R package.</p>
      </div>
      <div class="col-md-3 col-lg-3 d-none d-md-block sidebar"></div>
    </div>
  </div>
</footer>
</body>
</html>
